package com.example.baselibrary.utils

import java.text.SimpleDateFormat
import java.util.*

object MyTimeUtils {
    /**
     * 获取10位时间戳
     */
    fun get10TimeLong(): Long {
        val currentdate = Date()
        val stData = currentdate.time.toString()
        val time = stData.substring(0, 10).toLong()
        return time
    }

    /**
     * 获取当前年月
     */
    fun getYerMoth(): String {
        val format = SimpleDateFormat("yyyy-MM")
        return format.format(Date()).toString()
    }

    fun getYerMoth1(): String {
        val format = SimpleDateFormat("yyyy年MM月")
        return format.format(Date()).toString()
    }

    //年月日时分秒格式
    fun getTimes(date: Date): String? {
        val format = SimpleDateFormat("yyyy-MM")
        return format.format(date)
    }

    //年月
    fun getTimesYe(date: Date): String? {
        val format = SimpleDateFormat("yyyy年MM")
        return format.format(date)
    }

    fun getTimesYeMOTH(): String? {
        val format = SimpleDateFormat("yyyy-MM--dd hh:ss")
        return format.format(Date()).toString()
    }

    fun timeConversion(time: Int): String {
        var hour = 0
        var minutes = 0
        var sencond = 0
        val temp = time % 3600
        if (time > 3600) {
            hour = time / 3600
            if (temp != 0) {
                if (temp > 60) {
                    minutes = temp / 60
                    if (temp % 60 != 0) {
                        sencond = temp % 60
                    }
                } else {
                    sencond = temp
                }
            }
        } else {
            minutes = time / 60
            if (time % 60 != 0) {
                sencond = time % 60
            }
        }
//        (if (hour < 10) "0$hour" else hour).toString() +
        return "" + (if (minutes < 10) "0$minutes" else minutes) + ":" + if (sencond < 10) "0$sencond" else sencond
    }
}